package com.yehui.alibaba.service.tcc;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;

/**
 * @author 业徽
 * @date 2021/8/4
 */
@LocalTCC
public interface TCCAccountService {

    /**
     * 扣除余额
     *
     * @param userId 用户编号
     * @param price  扣减金额
     * @throws Exception 失败时抛出异常
     */
    @TwoPhaseBusinessAction(name = "AccountServiceTCC", commitMethod = "tccCommit", rollbackMethod = "tccRollback")
    void reduceBalance(BusinessActionContext actionContext, @BusinessActionContextParameter(paramName = "userId") Long userId,
                              @BusinessActionContextParameter(paramName = "price") Integer price) throws Exception;


    /**
     * Commit boolean.
     *
     * @param actionContext the action context
     * @return the boolean
     */
    boolean tccCommit(BusinessActionContext actionContext);

    /**
     * Rollback boolean.
     *
     * @param actionContext the action context
     * @return the boolean
     */
    boolean tccRollback(BusinessActionContext actionContext);

}
